Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document huggingface_hub.get_safetensors_metadata #417

Merged
merged 5 commits into from
Jan 4, 2024

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Jan 4, 2024

Related to huggingface/huggingface_hub#1855 (cc @LysandreJik @julien-c).

Since 0.20.0, huggingface_hub has an helper to parse safetensors metadata. This PR updates the documentation by replacing the previous "raw" snippet with this new one. The Python and JS snippets are now similar.

Wauplin and others added 3 commits January 4, 2024 11:18
Co-authored-by: Mishig <dmishig@gmail.com>
Co-authored-by: Mishig <dmishig@gmail.com>
@Wauplin
Copy link
Contributor Author

Wauplin commented Jan 4, 2024

Thanks for the review @mishig25. I adressed all 3 comments.

Copy link
Collaborator

@mishig25 mishig25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks for updating the docs !

Co-authored-by: Mishig <dmishig@gmail.com>
@mishig25 mishig25 merged commit 3c68e59 into main Jan 4, 2024
5 of 11 checks passed
@mishig25 mishig25 deleted the document-python-metadata-parsing branch January 4, 2024 11:00
Comment on lines -101 to -115
def parse_single_file(url):
# Fetch the first 8 bytes of the file
headers = {'Range': 'bytes=0-7'}
response = requests.get(url, headers=headers)
# Interpret the bytes as a little-endian unsigned 64-bit integer
length_of_header = struct.unpack('<Q', response.content)[0]
# Fetch length_of_header bytes starting from the 9th byte
headers = {'Range': f'bytes=8-{7 + length_of_header}'}
response = requests.get(url, headers=headers)
# Interpret the response as a JSON object
header = response.json()
return header

url = "https://huggingface.co/gpt2/resolve/main/model.safetensors"
header = parse_single_file(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this was still valuable to show how it actually works, no? potentially mentioning the huggingface_hub support at the end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking @mishig25's PR: #424 (thanks about that 🙏)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants